import { ApiProperty } from "@nestjs/swagger";
import { BaseEntity } from "src/common/entities/entities";
import { Column, Entity, JoinColumn, ManyToMany, ManyToOne, Unique } from "typeorm";
import { MovieEntity } from "../../movies/entities/movie.entity";
import { FreeState, Status } from "src/dictionaries/index.enum";
@Entity('movies-episode')
@Unique(['movies', 'episodeNumber']) // 同一个剧集中 episodeNumber 唯一
export class MoviesEpisodeEntity extends BaseEntity {
    /** 名称 */
    @ApiProperty({ example: 'name', description: '名称' })
    @Column({
        type: 'varchar',
        comment: '名称',
        length: 50,
    })
    name: string;

    /** 集编号 */
    @ApiProperty({ example: 'sort', description: '集编号' })
    @Column({ type: 'int', comment: '集编号', default: 1 })
    episodeNumber: number;

    /** mp4 */
    @ApiProperty({ example: 'mp4', description: 'mp4' })
    @Column({
        type: 'text',
        comment: 'mp4',
        nullable: true
    })
    mp4: string;
    /** 剧情图片 */
    @ApiProperty({ example: 'cover', description: '剧情图片' })
    @Column({
        type: 'text',
        comment: '剧情图片',
    })
    cover: string;


    /** 观看剧集所需金额 */
    @ApiProperty({ example: 'amount', description: '观看剧集所需金额' })
    @Column({
        type: 'decimal',
        precision: 10,
        scale: 2,
        comment: '观看剧集所需金额',
        default: 0
    })
    amount: number;

    /** 是否免费 */
    @ApiProperty({
        enum: FreeState,
        example: FreeState.FREE,
        description: '是否免费（1：免费，2：付费）',
    })
    @Column({
        type: 'enum',
        enum: FreeState,
        default: FreeState.FREE,
    })
    free: FreeState;

    /** 是否上架 */
    @ApiProperty({
        enum: Status,
        example: Status.ENABLED,
        description: '是否上架状态',
    })
    @Column({
        type: 'enum',
        enum: Status,
        default: Status.ENABLED,
    })
    status: Status;

    /** 点赞数 */
    @ApiProperty({ example: 1000, description: '点赞数' })
    @Column({
        type: 'int',
        comment: '点赞数',
        default: 0,
    })
    likeCount: number;

    /** 播放量 */
    @ApiProperty({ example: 1000, description: '播放量' })
    @Column({
        type: 'int',
        comment: '播放量',
        default: 0,
    })
    playCount: number;

    /** 收藏量 */
    @ApiProperty({ example: 1000, description: '收藏量' })
    @Column({
        type: 'int',
        comment: '收藏量',
        default: 0,
    })
    collectCount: number;

    @ApiProperty({ example: 'moviesId', description: '电影ID' })
    @Column({ type: 'int', comment: '电影ID' })
    moviesId: number;

    /** 关联的电影实体 */
    @ManyToOne(() => MovieEntity, (movies) => movies.episodes)
    @JoinColumn({ name: 'moviesId' })
    movies: MovieEntity;
}
